#!/usr/bin/env python
import os, sys, string, sliplib, slide, codecs

#XML to SLiP conversion

strHelp = """
USAGE: xml2slip [-h] [<input XML file> [<optional output SLiP file>]]

Options:
	-h : print this help screen
"""

if sys.argv[1] in ["-h", "-H"]:
	print strHelp
	sys.exit(0)


slide.booVerbose = 0
pathXML = sys.argv[1]


if len(sys.argv) <= 2:
	pathSLIP = ""
else:
	pathSLIP = sys.argv[2]



#convert xml file to slip file

slide.openFile(pathXML)


#convert line breaks into OS friendly linebreaks for editing
strFormattedLineBreaksSLIP = string.replace(slide.objCurrDocInstance.SLIP, u"\n", os.linesep)

if not pathSLIP == "":
	fdSLIP = codecs.open(pathSLIP, "w", slide.objCurrDocInstance.SLIPencoding)
	fdSLIP.write(strFormattedLineBreaksSLIP)
	fdSLIP.close()
	
else:
	sys.stdout.write(strFormattedLineBreaksSLIP.encode(slide.objCurrDocInstance.SLIPencoding))


slide.closeFile()
sys.exit(0)
